From 93fa4c1640aad29d8c0ce410654d72059e115a77 Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Mon, 23 Feb 2015 16:14:34 -0800 Subject: [PATCH] Download registry packages on `cargo fetch` Closes #1329 --- src/cargo/ops/cargo_fetch.rs | 11 ++++++++--- src/registry/lib.rs | 2 +- tests/test_cargo_registry.rs | 24 ++++++++++++++++++++++++ 3 files changed, 33 insertions(+), 4 deletions(-) diff --git a/src/cargo/ops/cargo_fetch.rs b/src/cargo/ops/cargo_fetch.rs index 682d84f43..9ba0f0058 100644 --- a/src/cargo/ops/cargo_fetch.rs +++ b/src/cargo/ops/cargo_fetch.rs @@ -1,8 +1,8 @@ use core::registry::PackageRegistry; -use core::source::Source; +use core::{Source, PackageId}; use ops; use sources::PathSource; -use util::{CargoResult, Config}; +use util::{CargoResult, Config, human, ChainError}; /// Executes `cargo fetch`. pub fn fetch(manifest_path: &Path, config: &Config) -> CargoResult<()> { @@ -12,6 +12,11 @@ pub fn fetch(manifest_path: &Path, config: &Config) -> CargoResult<()> { let package = try!(source.root_package()); let mut registry = PackageRegistry::new(config); - try!(ops::resolve_pkg(&mut registry, &package)); + let resolve = try!(ops::resolve_pkg(&mut registry, &package)); + + let ids: Vec = resolve.iter().cloned().collect(); + try!(registry.get(&ids).chain_error(|| { + human("unable to get packages from source") + })); Ok(()) } diff --git a/src/registry/lib.rs b/src/registry/lib.rs index 887264fc5..75b89624f 100644 --- a/src/registry/lib.rs +++ b/src/registry/lib.rs @@ -1,4 +1,4 @@ -#![feature(core, io)] +#![feature(core, io, path)] extern crate curl; extern crate "rustc-serialize" as rustc_serialize; diff --git a/tests/test_cargo_registry.rs b/tests/test_cargo_registry.rs index 8e2435351..7db4eb9dc 100644 --- a/tests/test_cargo_registry.rs +++ b/tests/test_cargo_registry.rs @@ -707,3 +707,27 @@ test!(update_publish_then_update { dir = p.url()).as_slice())); }); + +test!(fetch_downloads { + let p = project("foo") + .file("Cargo.toml", r#" + [project] + name = "foo" + version = "0.5.0" + authors = [] + + [dependencies] + a = "0.1.0" + "#) + .file("src/main.rs", "fn main() {}"); + p.build(); + + r::mock_pkg("a", "0.1.0", &[]); + + assert_that(p.process(cargo_dir().join("cargo")).arg("fetch"), + execs().with_status(0) + .with_stdout(format!("\ +{updating} registry `[..]` +{downloading} a v0.1.0 (registry [..]) +", updating = UPDATING, downloading = DOWNLOADING))); +}); -- 2.30.2